home *** CD-ROM | disk | FTP | other *** search
/ AMIGA-CD 2 / Amiga-CD - Volume 2.iso / ungepackte_daten / 1995 / 4 / 02 / kartentricks / listing2.c < prev    next >
C/C++ Source or Header  |  1995-06-01  |  5KB  |  156 lines

  1. #include <intuition/intuitionbase.h>
  2. #include <graphics/displayinfo.h>
  3. #include <graphics/gfxbase.h>
  4. #include <clib/intuition_protos.h>
  5. #include <clib/graphics_protos.h>
  6. #include <clib/exec_protos.h>
  7. #include <stdio.h>
  8.  
  9. struct IntuitionBase *IntuitionBase;
  10. struct GfxBase       *GfxBase;
  11. struct Screen        *Workbench;
  12. struct BitMap        *BitMap;
  13. struct DisplayInfo    DisplayInfo;
  14. struct DimensionInfo  DimensionInfo;
  15.  
  16. ULONG                 DisplayID;
  17. ULONG                 Flags;
  18. ULONG                 BitMapDepth, BitMapWidth;
  19. WORD                  MaxDepth;
  20. UWORD                 NumSprites;
  21.  
  22. int main(void)
  23. {
  24.   if(IntuitionBase = (struct IntuitionBase *)
  25.       OpenLibrary("intuition.library",37))
  26.   {
  27.     if(GfxBase = (struct GfxBase *)
  28.         OpenLibrary("graphics.library",37))
  29.     {
  30.       if(Workbench = LockPubScreen("Workbench"))
  31.       {
  32.         DisplayID = GetVPModeID(&Workbench -> ViewPort);
  33.  
  34.         /*
  35.          * Farbtiefe der Workbench bestimmen
  36.          */
  37.  
  38.         if(GetDisplayInfoData(NULL, (APTR)&DimensionInfo,
  39.             sizeof(struct DimensionInfo), DTAG_DIMS,
  40.             DisplayID))
  41.         {
  42.             MaxDepth = DimensionInfo . MaxDepth;
  43.             printf("Maximale Tiefe für 0x%08x = %d "
  44.                    "(%d Farben)\n", DisplayID, MaxDepth,
  45.                    1L << MaxDepth);
  46.         }
  47.  
  48.         /*
  49.          * Bittiefen der einzelnen Farben bestimmen
  50.          */
  51.  
  52.         if(GetDisplayInfoData(NULL, (APTR)&DisplayInfo,
  53.             sizeof(struct DisplayInfo), DTAG_DISP, DisplayID))
  54.         {
  55.           if(GfxBase -> LibNode . lib_Version < 39)
  56.           { LONG i;
  57.             for(i = 1 ; i < 16 ; i++)
  58.             {  if(i * i * i >= DisplayInfo.PaletteRange)
  59.                    break;
  60.             }
  61.  
  62.             printf("Palette für 0x%08lx: %d × %d × %d = "
  63.                    "%d Farbwerte\n",DisplayID,i,i,i,
  64.                    DisplayInfo . PaletteRange);
  65.           }
  66.           else
  67.           { printf("Palette für 0x%08lx: %d × %d × %d = "
  68.                    "%d Farbwerte\n", DisplayID,
  69.               1L << DisplayInfo . RedBits,
  70.               1L << DisplayInfo . GreenBits,
  71.               1L << DisplayInfo . BlueBits,
  72.               (1L << DisplayInfo . RedBits)   *
  73.               (1L << DisplayInfo . GreenBits) *
  74.               (1L << DisplayInfo . BlueBits)    );
  75.           }
  76.         }
  77.  
  78.         /*
  79.          * BitMap-Eigenschaften bestimmen
  80.          *
  81.          * Hinweis: Statt &Workbench->BitMap ist
  82.          *                 Workbench->RastPort.BitMap vorzuziehen
  83.          */
  84.  
  85.         BitMap = Workbench->RastPort.BitMap;
  86.         Flags = GetBitMapAttr(BitMap,BMA_FLAGS);
  87.         printf("BitMap-Eigenschaften des Workbench-Screens:\n");
  88.  
  89.         if(Flags & BMF_STANDARD)
  90.             printf("Die Grafikdaten liegen als Bitplanes"
  91.                    " im Chip-RAM vor.\n");
  92.         else
  93.             printf("Diese BitMap wurde vom Grafikkartentreiber"
  94.                    " erzeugt.\n");
  95.  
  96.         /*
  97.          * BitMap-Daten auslesen
  98.          *
  99.          * Wichtig: immer die BitMap aus dem RastPort des
  100.          *      Screens verwenden, *niemals* Screen->BitMap. */
  101.  
  102.         BitMap = Workbench -> RastPort . BitMap;
  103.         printf("Workbench im Modus 0x%08x, %d x %d\n",DisplayID,
  104.             Workbench -> Width,Workbench -> Height);
  105.  
  106.         /* So sollte man es eigentlich nicht machen, aber
  107.          * dieses Programmstück dient nur der Demonstration. */
  108.         printf("BytesPerRow = %d Depth = %d\n",
  109.                 BitMap->BytesPerRow, BitMap -> Depth);
  110.  
  111.         /* So fragt man Informationen über die BitMap ab. */
  112.         if(GfxBase -> LibNode . lib_Version >= 39)
  113.         {
  114.             BitMapDepth = GetBitMapAttr(BitMap,BMA_DEPTH);
  115.             BitMapWidth = GetBitMapAttr(BitMap,BMA_WIDTH);
  116.             printf("BitMap: Depth %d\n",BitMapDepth);
  117.             printf("BitMap: Width %d\n",BitMapWidth);
  118.         }
  119.  
  120.         /*
  121.          * Größe des Bildschirmbereichs bestimmen
  122.          */
  123.  
  124.         if(GetDisplayInfoData(NULL, (APTR)&DimensionInfo,
  125.             sizeof(struct DimensionInfo), DTAG_DIMS, DisplayID))
  126.         {
  127.             printf("Minimale Größe für 0x%08x = %d x %d\n",
  128.                     DisplayID, DimensionInfo.MinRasterWidth,
  129.                                DimensionInfo.MinRasterHeight);
  130.  
  131.             printf("Maximale Größe für 0x%08x = %d x %d\n",
  132.                     DisplayID, DimensionInfo.MaxRasterWidth,
  133.                                DimensionInfo.MaxRasterHeight);
  134.         }
  135.  
  136.         /*
  137.          * Anzahl der verfügbaren Sprites bestimmen
  138.          */
  139.  
  140.         if(GetDisplayInfoData(NULL,(APTR)&DisplayInfo,
  141.             sizeof(struct DisplayInfo),DTAG_DISP, DisplayID))
  142.         {
  143.             NumSprites = DisplayInfo . NumStdSprites;
  144.             printf("Anzahl Sprites für 0x%08x = %d\n",
  145.                 DisplayID,NumSprites);
  146.         }
  147.  
  148.         UnlockPubScreen(NULL,Workbench);
  149.       }
  150.       CloseLibrary(GfxBase);
  151.     }
  152.   CloseLibrary(IntuitionBase);
  153.   }
  154.   return(0);
  155. }
  156.